/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.CustomerManager;

import BLL.Customer_BLL;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Mr.Sam
 */
public class SearchCustomer extends javax.swing.JInternalFrame {

    /**
     * Creates new form SearchCustomer
     */
    TableCustomer model=new TableCustomer();
    Customer_BLL customer_bll=new Customer_BLL();
    String sql="select * from customer";
    public SearchCustomer() throws Exception {
        initComponents();
        model.SetTable(Table);
        model.SetData(sql);
    }
    public void ReloadTable(String sql)
    {
        this.sql=sql;
        model.RemoveData();
        try {
            model.SetData(sql);
        } catch (Exception ex) {
            Logger.getLogger(SearchCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jLabel1 = new javax.swing.JLabel();
        MaKH = new javax.swing.JTextField();
        CMND = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        Email = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        HoTen = new javax.swing.JTextField();
        DiaChi = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        SoDienThoai = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        Table = new org.jdesktop.swingx.JXTable();

        jLabel1.setText("Mã Khách Hàng");

        MaKH.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                MaKHCaretUpdate(evt);
            }
        });

        CMND.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                CMNDCaretUpdate(evt);
            }
        });

        jLabel2.setText("CMND");

        Email.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                EmailCaretUpdate(evt);
            }
        });

        jLabel3.setText("Email");

        jLabel4.setText("Tên Khách Hàng");

        HoTen.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                HoTenCaretUpdate(evt);
            }
        });

        DiaChi.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                DiaChiCaretUpdate(evt);
            }
        });

        jLabel5.setText("Địa Chỉ");

        jLabel6.setText("Số Điện Thoại");

        SoDienThoai.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                SoDienThoaiCaretUpdate(evt);
            }
        });

        Table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(Table);

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Email, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CMND, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(MaKH, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(65, 65, 65)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(SoDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(HoTen, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(353, Short.MAX_VALUE))
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(HoTen, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(DiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(SoDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(MaKH, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(CMND, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Email, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void MaKHCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_MaKHCaretUpdate
        // TODO add your handling code here:
        this.sql=customer_bll.Search(
                MaKH.getText()!="", MaKH.getText()!=""?MaKH.getText():"", 
                HoTen.getText()!="", HoTen.getText()!=""?HoTen.getText():"", 
                CMND.getText()!="", CMND.getText()!=""?CMND.getText():"", 
                DiaChi.getText()!="", DiaChi.getText()!=""?DiaChi.getText():"", 
                Email.getText()!="", Email.getText()!=""?Email.getText():"",
                SoDienThoai.getText()!="", SoDienThoai.getText()!=""?SoDienThoai.getText():""
                );
        ReloadTable(sql);
    }//GEN-LAST:event_MaKHCaretUpdate

    private void CMNDCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_CMNDCaretUpdate
        // TODO add your handling code here:
         this.sql=customer_bll.Search(
                MaKH.getText()!="", MaKH.getText()!=""?MaKH.getText():"", 
                HoTen.getText()!="", HoTen.getText()!=""?HoTen.getText():"", 
                CMND.getText()!="", CMND.getText()!=""?CMND.getText():"", 
                DiaChi.getText()!="", DiaChi.getText()!=""?DiaChi.getText():"", 
                Email.getText()!="", Email.getText()!=""?Email.getText():"",
                SoDienThoai.getText()!="", SoDienThoai.getText()!=""?SoDienThoai.getText():""
                );
        ReloadTable(sql);
    }//GEN-LAST:event_CMNDCaretUpdate

    private void EmailCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_EmailCaretUpdate
        // TODO add your handling code here:
         this.sql=customer_bll.Search(
                MaKH.getText()!="", MaKH.getText()!=""?MaKH.getText():"", 
                HoTen.getText()!="", HoTen.getText()!=""?HoTen.getText():"", 
                CMND.getText()!="", CMND.getText()!=""?CMND.getText():"", 
                DiaChi.getText()!="", DiaChi.getText()!=""?DiaChi.getText():"", 
                Email.getText()!="", Email.getText()!=""?Email.getText():"",
                SoDienThoai.getText()!="", SoDienThoai.getText()!=""?SoDienThoai.getText():""
                );
        ReloadTable(sql);
    }//GEN-LAST:event_EmailCaretUpdate

    private void HoTenCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_HoTenCaretUpdate
        // TODO add your handling code here:
         this.sql=customer_bll.Search(
                MaKH.getText()!="", MaKH.getText()!=""?MaKH.getText():"", 
                HoTen.getText()!="", HoTen.getText()!=""?HoTen.getText():"", 
                CMND.getText()!="", CMND.getText()!=""?CMND.getText():"", 
                DiaChi.getText()!="", DiaChi.getText()!=""?DiaChi.getText():"", 
                Email.getText()!="", Email.getText()!=""?Email.getText():"",
                SoDienThoai.getText()!="", SoDienThoai.getText()!=""?SoDienThoai.getText():""
                );
        ReloadTable(sql);
    }//GEN-LAST:event_HoTenCaretUpdate

    private void DiaChiCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_DiaChiCaretUpdate
        // TODO add your handling code here:
         this.sql=customer_bll.Search(
                MaKH.getText()!="", MaKH.getText()!=""?MaKH.getText():"", 
                HoTen.getText()!="", HoTen.getText()!=""?HoTen.getText():"", 
                CMND.getText()!="", CMND.getText()!=""?CMND.getText():"", 
                DiaChi.getText()!="", DiaChi.getText()!=""?DiaChi.getText():"", 
                Email.getText()!="", Email.getText()!=""?Email.getText():"",
                SoDienThoai.getText()!="", SoDienThoai.getText()!=""?SoDienThoai.getText():""
                );
        ReloadTable(sql);
    }//GEN-LAST:event_DiaChiCaretUpdate

    private void SoDienThoaiCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_SoDienThoaiCaretUpdate
        // TODO add your handling code here:
         this.sql=customer_bll.Search(
                MaKH.getText()!="", MaKH.getText()!=""?MaKH.getText():"", 
                HoTen.getText()!="", HoTen.getText()!=""?HoTen.getText():"", 
                CMND.getText()!="", CMND.getText()!=""?CMND.getText():"", 
                DiaChi.getText()!="", DiaChi.getText()!=""?DiaChi.getText():"", 
                Email.getText()!="", Email.getText()!=""?Email.getText():"",
                SoDienThoai.getText()!="", SoDienThoai.getText()!=""?SoDienThoai.getText():""
                );
        ReloadTable(sql);
    }//GEN-LAST:event_SoDienThoaiCaretUpdate

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField CMND;
    private javax.swing.JTextField DiaChi;
    private javax.swing.JTextField Email;
    private javax.swing.JTextField HoTen;
    private javax.swing.JTextField MaKH;
    private javax.swing.JTextField SoDienThoai;
    private org.jdesktop.swingx.JXTable Table;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    // End of variables declaration//GEN-END:variables
}
